package io.renren.modules.media.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.media.dao.PictureInfoDao;
import io.renren.modules.media.entity.PictureInfoEntity;
import io.renren.modules.media.service.PictureInfoService;


@Service("pictureInfoService")
public class PictureInfoServiceImpl extends ServiceImpl<PictureInfoDao, PictureInfoEntity> implements PictureInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String jobId = (String)params.get("jobId");
        String fileName = (String)params.get("fileName");
        
        IPage<PictureInfoEntity> page = this.page(
                new Query<PictureInfoEntity>().getPage(params),
                new QueryWrapper<PictureInfoEntity>()
                .like(StringUtils.isNotBlank(jobId),"job_id", jobId)
				.like(StringUtils.isNotBlank(fileName),"file_name", fileName)
        );

        return new PageUtils(page);
    }

	@Override
	public int saveInfo(String jobId, String fileName, String filePath,String fileFormat, Integer width, Integer height) {
		PictureInfoEntity info = new PictureInfoEntity(); 
		info.setJobId(jobId);
		info.setFileName(fileName);
		info.setFilePath(filePath);
		info.setFileFormat(fileFormat);
		info.setCreateTime(new Date());
		info.setWidth(width);
		info.setHeight(height);
		save(info);
		
		return info.getId();
	}

}